package com.mkj.listener;

import java.awt.*;

/**
 * @Author Arrebol
 * @Date 2024/8/4 12:16
 * @Project graphical programming
 * @Description：
 * 事件处理演示
 */
public class EventDemo1 {

    Frame frame=new Frame("这里测试事件处理");
    TextField textField=new TextField(30);
    Button button=new Button("确定");

    public static void main(String[] args) {
        new EventDemo1().init();
    }
    public void init(){
        //组装视图
        //事件监听器
        //MyListener listener=new MyListener();
        //注册监听
        button.addActionListener(e ->{
            System.out.println("按钮被点击");
            textField.setText("Hello World");
        });
        //将组件放入Frame
        frame.add(textField,BorderLayout.NORTH);
        frame.add(button);
        frame.pack();
        frame.setVisible(true);
    }

  /*  private class MyListener implements ActionListener{
        @Override
        public void actionPerformed(ActionEvent e) {
            textField.setText("Hello World");
        }
    }*/

}
